#

| Chapter 41 Terminal and Serial Line Settings |

## 41.7 Reading Verrrry Long Lines from the Terminal

Sometimes you can have a very long line of input that you want to write to a file. It might come from your personal computer, a device hooked to your terminal, or just an especially long set of characters that you have to type on the keyboard. Normally the UNIX terminal driver (42.1) holds all characters you type until it sees a line terminator or interrupt character. Most buffers have room for 256 characters.

If you're typing the characters at the keyboard, there's an easy fix: Hit CTRL-d every 200 characters or so to flush the input buffer. You won't be able to backspace before that point, but the shell will read everything in.

Or, to make UNIX pass each character it reads without buffering, use stty (41.3) to set your terminal to cbreak (or non-canonical) input mode. For example:

>     % stty cbreak
>     % cat > file
>     enter the very long line.........
>     [CTRL-c]
>     % stty -cbreak

On System V, start with `stty -icanon` and end with `stty icanon`.

While you're in cbreak mode, special keys like BACKSPACE or DELETE won't be processed; they'll be stored in the file. Typing CTRL-d will not make cat quit. To quit, kill cat by pressing your normal interrupt key - say, CTRL-c.

(If you accidentally type a backspace or press RETURN when you didn't want to, you can see those characters in the file with the octal dump command, od (25.7), and its -c option. Filter them out with tr -d (35.11) or a text editor (the GNU Emacs (32.1) editor can handle very long lines).)

One more problem: if you use a shell with built-in command line editing (11.13) and/or filename completion (9.8), they might cause you trouble because they use stty-like commands to let you edit. In that case, start a plain Bourne shell (type sh or /bin/sh) before you give the stty command.

- JP

41.6 Using sleep to Keep Port Settings |  | 41.8 ptys and Window Systems